<template>
	<view class="nav-container">
		<view v-for="(item, index) in icon" class="nav-box" @click="navToPage(icon[index].url)" :key="key">
			<image class="icon" :src="item.pic"></image>
			<text class="text">{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	import {
		goPage
	} from '../../../utils/crane.js'
	import {member} from "../../../api/crane.js"
	export default {
		props: {
			icon: {
				type: Array,
				default: [],
			},
		},
		components: {},
		name: 'navBar',
		data() {
			return {
				isflag: "select",
				navList: [{
						text: '吊装公司',
						icon: '/static/images/crane/navCompany.png',
						url: '/pages/companyList/index'
					},
					// {
					// 	text: '车型查询',
					// 	icon: '/static/images/crane/navSearch.png',
					// 	url: '/pages/searchCar/index',
					// }, 
					{
						text: '插销模拟',
						icon: '/static/images/crane/navSimulation.png',
						url: '/pages/barSimulator/index',
						type: 'tab'
					}, {
						text: '模拟教程',
						icon: '/static/images/crane/navTutorials.png',
						url: 'https://baidu.com',
						type: 'web'
					}, {
						text: '公司入驻',
						icon: '/static/images/crane/navSettleIn.png',
						url: '/pages/companySettled/index'
					}
				]
			};
		},
		onLoad(options) {
            console.log("本地",uni.getStorageSync("payVipDay"))
			
		},
		watch: {},
		onShow() {},
		onReady() {},
		methods: {
			navToPage: function(url) {
				let type = 'pages';
				if (url.startsWith('http')) {
					type = 'web'
				}
				if (url == "/pages/barSimulator/index") {
					member(this.$store.state.app.uid,this.isflag).then(res => {
						this.us=res.data.vipDay
						if(res.data.isNewUser==0){
							if(res.data.vipDay==0){
								uni.showModal({
									title:"提示",
									content:"您的会员已到期，请点击确定按钮，前往充值会员",
									success:function(res) {
										if(res.confirm){
											console.log("确定")
											uni.navigateTo({
												url:"/pages/users/user_vip/index"
											})
										}else if(res.cancel){
											uni.navigateBack(1)
										}
									}
								})
							}
							if(res.data.vipDay>=1){
								
								uni.switchTab({
									url: "/pages/barSimulator/index"
								})
							}
						
						}
						if(res.data.isNewUser==1){
							var that=this
							uni.showModal({
								title:"提示",
								content:"您是当前系统新用户，免费享受3天VIP会员特权",
								success:function(res) {
									if(res.confirm){
										
									uni.switchTab({
										url: "/pages/barSimulator/index"
									})
									}else{
										uni.navigateBack(1)
									}
								}
							})
						}
					})
				

				}
				if (url == "/pages/barSimulator/index" && this.huiyuan == 2) {
					uni.switchTab({
						url: "/pages/barSimulator/index"
					})

				}

				if (url == "/pages/companySettled/index?reqtype=2") {
					member(this.$store.state.app.uid,this.isflag).then(res => {
						if(res.data.isCreateCom==0){
							uni.navigateTo({
								url: "/pages/companySettled/index"
							})
						}else{
							uni.showModal({
								title:"提示",
								content:"您当前已创建公司，确认跳转公司详情",
								success:function(res) {
									if(res.confirm){
									uni.navigateTo({
										url: "/pages/companyDetails/newindex"
									})
									}else{
										uni.navigateBack(1)
									}
								}
							})
						}
						
					})
					
					// uni.navigateTo({
					// 	url: "/pages/companySettled/index?reqtype=2"
					// })
				}
				if (url == "/pages/video_page/index?url=crmebvideo/sim.mp4") {
					uni.navigateTo({
						url: "/pages/video_page/index"
					})
				}
				if (url == "/pages/companyList/index") {
					uni.navigateTo({
						url: "/pages/companyList/index"
					})
				}

				console.log(11111, url);
				goPage({
					url,
					type
				})
			}
		}
	};
</script>

<style lang="scss">
	.nav-container {
		display: flex;
		justify-content: space-around;
		padding: 50upx 6upx 54upx;

		.nav-box {
			display: flex;
			flex-direction: column;
			flex-wrap: wrap;
			align-items: center;
			justify-content: space-between;
			flex: 0 0 88upx;
			width: 88upx;

			.icon {
				width: 84upx;
				flex: 0 0 84upx;
				height: 84upx;
				margin-bottom: 20upx;
				border-radius: 50%;
			}

			.text {
				line-height: 30upx;
				font-size: 22upx;
			}
		}
	}
</style>
